/*
	The MIT License

	Copyright (c) 2010 IFMO/GameDev Studio

	Permission is hereby granted, free of charge, to any person obtaining a copy
	of this software and associated documentation files (the "Software"), to deal
	in the Software without restriction, including without limitation the rights
	to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
	copies of the Software, and to permit persons to whom the Software is
	furnished to do so, subject to the following conditions:

	The above copyright notice and this permission notice shall be included in
	all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
	OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
	THE SOFTWARE.
*/


#pragma once

/*-----------------------------------------------------------------------------
	game entity class :
-----------------------------------------------------------------------------*/

class EGEntity;
typedef HardRef<EGEntity>	EHrGEntity;

struct EGCharDesc {
		float	height;
		float	width;
		float	climb_slope;
		float	stair_step;
		float	gravity;
	};


class EGEntity : public ICoreObject {
	public:
					EGEntity				( uint id );
					~EGEntity				( void );
					
		void		Update					( uint dtime );
		void		UpdateScript			( uint dtime );

		void		GetTable				( lua_State *L );
		void		SetTable				( lua_State *L, int idx );
					
		void		SetPose					( const EPoint &p, const EQuaternion &q );
		void		GetPose					( EPoint &p, EQuaternion &q ) const;
		
		void		SetupRendModel			( const EString &path );
		void		SetupRigidbody			( const EString &path, float mass );
		void		SetupCharacter			( const EGCharDesc &char_desc );
		void		SetupShip				( lua_State *L, int tidx );
		
		void		CharacterMove			( const EVector &dir, bool &floor, bool &ceil, bool &walls );
		
	protected:
		uint	id;
		int		table_ref;
		
		EPoint		position;
		EQuaternion	orient;
		
		void		UpdatePosition			( void );
		void		Unsetup					( void );

	public:
		HardRef<ERendModel>	rendmodel;
		
		struct Rigidbody {
			float			mass;
			IPxPhysEntity	entity;
		} rigidbody;
		
		
		struct Character {
			EGCharDesc			desc;
			IHrPhysCharacter	character;
		} character;
		
		
		struct Ship {
			EPxGShip	ship;
		} ship;
		
		
		struct Mover {
			int	__dummy__;
		} mover;

		
		struct Trigger {
			int	__dummy__;
		} trigger;

	};


